﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using F_SER.DAL;
using System.Data.SqlClient;
using System.Data;
using F_SER.Module;

namespace F_SER.BLL
{
    /// <summary>
    /// 联通绑定验证接口,缴费接口
    /// </summary>
    public class TelPortBll
    {
        /// <summary>
        /// 绑定验证接口
        /// </summary>
        /// <param name="admin">授权账号</param>
        /// <param name="pwd">授权密码</param>
        /// <param name="tel">电话</param>
        /// <param name="cardId">一卡通号</param>
        /// <param name="cid">身份证</param>
        /// <returns></returns>
        public string checkBind(string admin, string pwd, string tel, string cardId, string cid)
        {

            Module.SysInfo sys = new Module.SysInfo();
            sys.CMD = "01";
            sys.value01 = admin;
            sys.value02 = pwd;
            sys.value03 = tel;
            sys.value04 = cardId;
            sys.value06 = cid;

            string xml = CodeHelper.xml(sys);

            SqlHelper sqlhelper = new SqlHelper();
            SqlParameter[] para = new SqlParameter[]
					{
						new SqlParameter("AS_IN", xml),
						new SqlParameter("AS_OUT", SqlDbType.VarChar, 1024 ), //输出参数
					};
            para[0].Direction = ParameterDirection.Input;
            para[1].Direction = ParameterDirection.Output;
            sqlhelper.RunProc("[ZP_Ports]", para);
            string respMessage = para[1].Value.ToString();
            return respMessage;
        }
        /// <summary>
        /// 话费自动续费接口
        /// </summary>
        /// <param name="tel"></param>
        /// <param name="cardId"></param>
        /// <param name="monery"></param>
        /// <param name="admin"></param>
        /// <param name="pwd"></param>
        /// <returns></returns>
        public TelPort Renew( string admin, string pwd,string tel, string cardId, double monery,string cid )
        {
         
           Module.SysInfo sys = new Module.SysInfo();
            sys.CMD = "02";
            sys.value01 = admin;
            sys.value02 = pwd;
            sys.value03 = tel;
            sys.value04 = cardId;
            sys.value05 = monery.ToString();
            sys.value06 = cid;
           
            string xml = CodeHelper.xml(sys);

            SqlHelper sqlhelper = new SqlHelper();
            SqlParameter[] para = new SqlParameter[]
					{
						new SqlParameter("AS_IN", xml),
						new SqlParameter("AS_OUT", SqlDbType.VarChar, 1024 ), //输出参数
					};
            para[0].Direction = ParameterDirection.Input;
            para[1].Direction = ParameterDirection.Output;
            sqlhelper.RunProc("[ZP_Ports]", para);
            string respMessage=  para[1].Value.ToString();
            Module.TelPort TelPortMode = new Module.TelPort();
            TelPortMode.merchantID = admin;
            TelPortMode.CardID = cardId;
            TelPortMode.Tel = tel;
            TelPortMode.tranAmt = monery;
            TelPortMode.tranCode = "1316545";
            TelPortMode.tranDateTime = DateTime.Now;
            TelPortMode.respCode = respMessage.Substring(0,4);
            TelPortMode.respDesc = respMessage;
            return TelPortMode;
        }
    }
}